
var personlist;



function searchPerson(){
	$.get("../record/personnelquerylist",{'val':$("#str").val()},function(r){
		personlist=r.list;
		var html;
		html='<tr><th>名称</th><th>身份证</th><th>联系方式</th><th>标签编号</th><th>组名</th></tr>';
		$.each(personlist,function(index,item){
			html+='<tr onclick="getCodeTag('+item.code_tag+')" data-dismiss="modal"><td>'+item.name+'</td><td>'+item.nric+'</td><td>'+item.contact+'</td><td>'+item.code_tag+'</td><td>'+item.group_name+'</td></tr>';
		});
		$("#personlist").html(html);
	});
}
function getCodeTag(tag){
	var val=document.getElementById("val");
	val.value=tag;
}

/*document.getElementById("search").addEventListener("click", function(){
	startCurrentRequest();
});*/

    
var list;
var map=document.getElementById("map");
var nodeCircle;
//执行获取实时人员位置
function startCurrentRequest(){
	
	$.get("../record/personnelhistorylocationpostionlist",{'val':$("#val").val(),'dtFrom':$("#d4311").val(),'dtTo':$("#d4312").val()},function(r){
	
 	list=r.list;
 	$("#map").empty();
 	//清空map内容
	 
 	//再加回地图

 	var c=document.getElementById("areaMap");
 	  	var w = c.offsetWidth;
 	  	var html='<image  x="0" y="0" width="100%" xlink:href="../images/map2.svg" /><svg   xmlns="http://www.w3.org/2000/svg">';
 	     $.each(list,function(index,item){
 	     	
 	    	 //获取div的offsetWidth,对加入的坐标进行校
 	      	 var yuan_x=item.px;
 	      	 var yuan_y=item.py;
 	      	 
 	      	var yuan_x1=item.px1;
 	     	 var yuan_y1=item.py1;
 	     	 
 	     
 	     	var x = (w*yuan_x)/1800.0;
 	     	var h = w/2.0;
 	     	var y = (h*yuan_y)/900.0;
 	     	
 	     	var x1 = (w*yuan_x1)/1800.0;
 	     	var y1 = (h*yuan_y1)/900.0;
 	     	 
 	    /* 	 setTimeout(function(){addContent(yuan_x,yuan_y,yuan_x1,yuan_y1)},index*200);*/
 	       
 	     	if(index===0){
 	     	html+='<circle cx="'+x+'" cy="'+y+'" r="4" stroke="black" stroke-width="0" fill="red">';
 	     	}
 	     	var time=index*0.3;
 	  
 	     	html+='<animate attributeName="cx" from="'+x+'" to="'+x1+'" begin="'+time+'s" dur="0s"  />'
 			  +'<animate attributeName="cy" from="'+y+'" to="'+y1+'" begin="'+time+'s" dur="0s"  />';
 	   
 	   	 });
 	 	html+='</circle></svg>';
 	 	
 	 
 	     map.innerHTML=html;
 	     $.each(list,function(index,item){
 	      	
 	    	 //获取div的offsetWidth,对加入的坐标进行校
 	      	 var yuan_x=item.px;
 	      	 var yuan_y=item.py;
 	      	 
 	      	var yuan_x1=item.px1;
 	     	 var yuan_y1=item.py1;
 	     	 
 	     
 	     	var x = (w*yuan_x)/1800.0;
 	     	var h = w/2.0;
 	     	var y = (h*yuan_y)/900.0;
 	     	
 	     	var x1 = (w*yuan_x1)/1800.0;
 	     	var y1 = (h*yuan_y1)/900.0;
 	     	 
 	    /* 	 setTimeout(function(){addContent(yuan_x,yuan_y,yuan_x1,yuan_y1)},index*200);*/
 	       
 	  	addContent(x,y,x1,y1);

 	     	
 	   
 	   	 });
 	   
    }); 
	

  
}
function addContent(x,y,x1,y1){


//动态创建svg的line

	var c1= document.createElementNS("http://www.w3.org/2000/svg", "line");
 
	c1.setAttribute("x1", x);  
		c1.setAttribute("y1", y); 
		c1.setAttribute("x2", x1);  
		c1.setAttribute("y2", y1); 
	   c1.setAttribute("stroke-width", "2");

	c1.setAttribute("stroke", "rgb(99,99,99)");

	map.appendChild(c1);
}
